package com.bank.common;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
 
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
 
public class pdfGenerator {
 
    public void createPDF(){
   	 try {
		 
         OutputStream file = new FileOutputStream(new File("D:\\PDF_Test.pdf"));
         Document document = new Document();
         PdfWriter.getInstance(document, file);

       //Inserting Table in PDF
            PdfPTable table=new PdfPTable(3);

                    PdfPCell cell = new PdfPCell (new Paragraph ("User data"));

                 cell.setColspan (3);
                 cell.setHorizontalAlignment (Element.ALIGN_CENTER);
                 cell.setPadding (10.0f);
                 cell.setBackgroundColor (new BaseColor (140, 221, 8));                                   

                 table.addCell(cell);                                     

                 table.addCell("Name");
                 table.addCell("ID");
                 table.addCell("Number");
                 table.addCell("-//-");
                 table.addCell("12345");
                 table.addCell("6785435");
                 table.addCell("-//-");
                 table.addCell("12345");
                 table.addCell("6785435");
                 table.addCell("-//-");
                 table.addCell("12345");
                 table.addCell("6785435");
                 table.setSpacingBefore(30.0f);       // Space Before table starts, like margin-top in CSS
                 table.setSpacingAfter(30.0f);        // Space After table starts, like margin-Bottom in CSS                                         

           

             //Now Insert Every Thing Into PDF Document
            document.open();//PDF document opened........                 

              

               document.add(Chunk.NEWLINE);   //Something like in HTML <img src="http://www.java4s.com/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley"> 

               document.add(new Paragraph("Document Generated On - "+new Date().toString()));  

               document.add(table);
               document.add(Chunk.NEWLINE);   //Something like in HTML <img src="http://www.java4s.com/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley">                                 

               document.newPage();            //Opened new page
                         
               document.close();

                    file.close();

       System.out.println("Pdf created successfully..");

   } catch (Exception e) {
       e.printStackTrace();
   }
    }
}